"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".

Replace these with more appropriate tests for your application.
"""

from django.test import TestCase
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext

from metodologia.models import Memoria, Processador
from metodologia.models import Solucao
from django.db import connection, transaction

from django.shortcuts import render_to_response
import MySQLdb
from settings import LOCAL


class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.failUnlessEqual(1 + 1, 2)
    
    def lista_10_componentes(self):
        if LOCAL:
            db = MySQLdb.connect(user='root', db='mysql_metogreen', passwd='cad123', host='localhost')
        else:
            db = MySQLdb.connect(user='metogreen', db='mysql_metogreen', passwd='metogreen1234', host='mysql.metogreen.ricardofiorelli.com')
        
        cursor = db.cursor()
        
        cursor.execute('SELECT MPN, description as name, 3CAT_ID, 2CAT_ID, 1CAT_ID FROM device WHERE 2CAT_ID=1 LIMIT 10')
        processadores = [row[0] for row in cursor.fetchall()]
        print processadores
        
        cursor.execute('SELECT MPN, description as name, 3CAT_ID, 2CAT_ID, 1CAT_ID FROM device WHERE 2CAT_ID=2 LIMIT 10')
        memorias = [row[0] for row in cursor.fetchall()]
        print memorias
        
        db.close()
